var api = (function () {
    return {
        _request(url, method, contentType, data) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    headers: {
                        authorization: '',
                        AccessControlAllowOrigin: "*"
                    },
                    contentType: contentType,
                    dataType: "json",
                    data: data,
                    url: `http://172.16.53.42:10004/${url}`,
                    type: method,
                    success: function (res, textStatus, request) {
                        // console.log(request.getResponseHeader("X-Total-Count"))
                        let data = { // 对请求回来的数据进行操作，修改数据格式
                            data: res,
                            total: request.getResponseHeader("X-Total-Count")
                        }
                        resolve(data)
                    }
                })
            })
        },
        get(url, params) {
            return new Promise((resolve, reject) => {
                this._request(url, "get", "application/json", params).then(res => {
                    if (res) {
                        resolve(res)
                    }
                })
            })
        },
        post(url, params) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    headers: {
                        authorization: '',
                    },
                    contentType: "application/json",
                    dataType: "json",
                    data: JSON.stringify(params),
                    url: `http://172.16.53.42:10004/${url}`,
                    type: "post",
                    success: function (res, textStatus, request) {
                        // console.log(request.getResponseHeader("X-Total-Count"))
                        let data = { // 对请求回来的数据进行操作，修改数据格式
                            data: res,
                            total: request.getResponseHeader("X-Total-Count")
                        }
                        resolve(data)
                    }
                })
            })
        },
        put(url, params) {
            return new Promise((resolve, reject) => {
                this._request(url, "put", "application/x-www-form-urlencoded", params).then(res => {
                    if (res) {
                        resolve(res)
                    }
                })
            })
        },
        delete(url, params) {
            return new Promise((resolve, reject) => {
                this._request(url, "delete", "application/json", params).then(res => {
                    if (res) {
                        resolve(res)
                    }
                })
            })
        }
    }
}())